--学生表修改
--创建序列
create sequence seq_user_student_version increment by 1 minvalue 1 no maxvalue start with 1;
--重置序列
--alter sequence seq_user_student_version restart with 1;
--字段绑定序列
alter table baseinfo.sc_user_student_update alter column update_pk set default nextval('seq_user_student_version');
--创建为触发器执行的函数:
CREATE OR REPLACE FUNCTION sc_user_student_update_func() RETURNS TRIGGER AS $sc_user_student_update_audit$
    BEGIN
        -- 在sc_user_student_update_audit中创建一行以反映在emp上执行的操作,
        -- 使用特殊的变量TG_OP来计算这个操作.
       IF (TG_OP = 'UPDATE') THEN
						--sc_user_student表执行删除操作时候,把修改的这条新数据放到sc_user_student_update表
						IF (NEW.status = '99') THEN
								insert into baseinfo.sc_user_student_update
								(
										fk_user,xh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,gatqwm,zzmmm,jkzkm,xyzjm,xxm,
										zp,sfzjyxq,dszybz,rxny,xslbm,xzz,hkszd,hkxzm,sfldrk,tc,lxdh,txdz,yzbm,dzxx,zydz,xjzh,create_by,
										create_time,update_by,update_time,xjfh,jzzlx,jzzhm,jzzyxq,cjlx,hksf,hkqx,hkdz,hjjd,xzzqx,sfspz,
										fk_unit,fk_grade,fk_class,rxfs,jdfs,dqzt,shzt,zcsj,zczt,wzcyy,sflsetm,sfge,sflshyfzn,sfxsyb,sfxsybm,
										yxxmc,fmsfshhk,zip_code,sfsxym,jb,hjlb,zwzcsj,hksq,yd,state,code,name,email,sex,status,old_pk,yhm,
										gzdw,bracelet_id,update_date,update_type
								)
								values
								(
										NEW.fk_user,NEW.xh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,
										NEW.gjdqm,NEW.sfzjlxm,NEW.sfzjh,NEW.gatqwm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,
										NEW.dszybz,NEW.rxny,NEW.xslbm,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.sfldrk,NEW.tc,NEW.lxdh,NEW.txdz,
										NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.xjzh,NEW.create_by,NEW.create_time,NEW.update_by,NEW.update_time,
										NEW.xjfh,NEW.jzzlx,NEW.jzzhm,NEW.jzzyxq,NEW.cjlx,NEW.hksf,NEW.hkqx,NEW.hkdz,NEW.hjjd,NEW.xzzqx,
										NEW.sfspz,NEW.fk_unit,NEW.fk_grade,NEW.fk_class,NEW.rxfs,NEW.jdfs,NEW.dqzt,NEW.shzt,NEW.zcsj,
										NEW.zczt,NEW.wzcyy,NEW.sflsetm,NEW.sfge,NEW.sflshyfzn,NEW.sfxsyb,NEW.sfxsybm,NEW.yxxmc,NEW.fmsfshhk,
										NEW.zip_code,NEW.sfsxym,NEW.jb,NEW.hjlb,NEW.zwzcsj,NEW.hksq,NEW.yd,NEW.state,NEW.code,NEW.name,
										NEW.email,NEW.sex,NEW.status,NEW.old_pk,NEW.yhm,NEW.gzdw,NEW.bracelet_id,
										cast(NEW.update_time as timestamp),3
								);
								RETURN NEW;
						ELSE
						--sc_user_student表执行修改操作时候,把修改的这条新数据放到sc_user_student_update表
								insert into baseinfo.sc_user_student_update
								(
										fk_user,xh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,gatqwm,zzmmm,jkzkm,xyzjm,xxm,
										zp,sfzjyxq,dszybz,rxny,xslbm,xzz,hkszd,hkxzm,sfldrk,tc,lxdh,txdz,yzbm,dzxx,zydz,xjzh,create_by,
										create_time,update_by,update_time,xjfh,jzzlx,jzzhm,jzzyxq,cjlx,hksf,hkqx,hkdz,hjjd,xzzqx,sfspz,
										fk_unit,fk_grade,fk_class,rxfs,jdfs,dqzt,shzt,zcsj,zczt,wzcyy,sflsetm,sfge,sflshyfzn,sfxsyb,sfxsybm,
										yxxmc,fmsfshhk,zip_code,sfsxym,jb,hjlb,zwzcsj,hksq,yd,state,code,name,email,sex,status,old_pk,yhm,
										gzdw,bracelet_id,update_date,update_type
								)
								values
								(
										NEW.fk_user,NEW.xh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,
										NEW.gjdqm,NEW.sfzjlxm,NEW.sfzjh,NEW.gatqwm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,
										NEW.dszybz,NEW.rxny,NEW.xslbm,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.sfldrk,NEW.tc,NEW.lxdh,NEW.txdz,
										NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.xjzh,NEW.create_by,NEW.create_time,NEW.update_by,NEW.update_time,
										NEW.xjfh,NEW.jzzlx,NEW.jzzhm,NEW.jzzyxq,NEW.cjlx,NEW.hksf,NEW.hkqx,NEW.hkdz,NEW.hjjd,NEW.xzzqx,
										NEW.sfspz,NEW.fk_unit,NEW.fk_grade,NEW.fk_class,NEW.rxfs,NEW.jdfs,NEW.dqzt,NEW.shzt,NEW.zcsj,
										NEW.zczt,NEW.wzcyy,NEW.sflsetm,NEW.sfge,NEW.sflshyfzn,NEW.sfxsyb,NEW.sfxsybm,NEW.yxxmc,NEW.fmsfshhk,
										NEW.zip_code,NEW.sfsxym,NEW.jb,NEW.hjlb,NEW.zwzcsj,NEW.hksq,NEW.yd,NEW.state,NEW.code,NEW.name,
										NEW.email,NEW.sex,NEW.status,NEW.old_pk,NEW.yhm,NEW.gzdw,NEW.bracelet_id,
										cast(NEW.update_time as timestamp),2
								);
								RETURN NEW;
						END IF;
        ELSIF (TG_OP = 'INSERT') THEN
				--sc_user_student表执行新增操作时候,把修改的这条新数据放到sc_user_student_update表
						insert into baseinfo.sc_user_student_update
						(
								fk_user,xh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,gatqwm,zzmmm,jkzkm,xyzjm,xxm,
								zp,sfzjyxq,dszybz,rxny,xslbm,xzz,hkszd,hkxzm,sfldrk,tc,lxdh,txdz,yzbm,dzxx,zydz,xjzh,create_by,
								create_time,update_by,update_time,xjfh,jzzlx,jzzhm,jzzyxq,cjlx,hksf,hkqx,hkdz,hjjd,xzzqx,sfspz,
								fk_unit,fk_grade,fk_class,rxfs,jdfs,dqzt,shzt,zcsj,zczt,wzcyy,sflsetm,sfge,sflshyfzn,sfxsyb,sfxsybm,
								yxxmc,fmsfshhk,zip_code,sfsxym,jb,hjlb,zwzcsj,hksq,yd,state,code,name,email,sex,status,old_pk,yhm,
								gzdw,bracelet_id,update_date,update_type
						)
						values
						(
								NEW.fk_user,NEW.xh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,
								NEW.gjdqm,NEW.sfzjlxm,NEW.sfzjh,NEW.gatqwm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,
								NEW.dszybz,NEW.rxny,NEW.xslbm,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.sfldrk,NEW.tc,NEW.lxdh,NEW.txdz,
								NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.xjzh,NEW.create_by,NEW.create_time,NEW.update_by,NEW.update_time,
								NEW.xjfh,NEW.jzzlx,NEW.jzzhm,NEW.jzzyxq,NEW.cjlx,NEW.hksf,NEW.hkqx,NEW.hkdz,NEW.hjjd,NEW.xzzqx,
								NEW.sfspz,NEW.fk_unit,NEW.fk_grade,NEW.fk_class,NEW.rxfs,NEW.jdfs,NEW.dqzt,NEW.shzt,NEW.zcsj,
								NEW.zczt,NEW.wzcyy,NEW.sflsetm,NEW.sfge,NEW.sflshyfzn,NEW.sfxsyb,NEW.sfxsybm,NEW.yxxmc,NEW.fmsfshhk,
								NEW.zip_code,NEW.sfsxym,NEW.jb,NEW.hjlb,NEW.zwzcsj,NEW.hksq,NEW.yd,NEW.state,NEW.code,NEW.name,
								NEW.email,NEW.sex,NEW.status,NEW.old_pk,NEW.yhm,NEW.gzdw,NEW.bracelet_id,
								cast(NEW.create_time as timestamp),1
						);
						RETURN NEW;
        END IF;
        RETURN NULL; -- result is ignored since this is an AFTER trigger
    END;
$sc_user_student_update_audit$ LANGUAGE plpgsql;

--为表sc_user_student添加触发器,然后执行的函数
--drop trigger sc_user_student_update_audit on baseinfo.sc_user_student;
CREATE TRIGGER sc_user_student_update_audit
AFTER INSERT OR UPDATE OR DELETE ON baseinfo.sc_user_student --在sc_user_student表每一行操作之后,执行增删查改时触发
FOR EACH ROW EXECUTE PROCEDURE sc_user_student_update_func();--执行的函数





--教师修改
create sequence seq_user_teacher_update_version increment by 1 minvalue 1 no maxvalue start with 1;
--重置序列
--alter sequence seq_user_teacher_update_version restart with 1;
--字段绑定序列
alter table baseinfo.sc_user_teacher_update alter column update_pk set default nextval('seq_user_teacher_update_version');
--创建为触发器执行的函数:
CREATE OR REPLACE FUNCTION sc_user_teacher_update_func() RETURNS TRIGGER AS $sc_user_teacher_update_audit$
    BEGIN
        -- 在sc_user_teacher_update_audit中创建一行以反映在emp上执行的操作,
        -- 使用特殊的变量TG_OP来计算这个操作.
       IF (TG_OP = 'UPDATE') THEN
						--sc_user_teacher表执行删除操作时候,把修改的这条新数据放到sc_user_teacher_update表
						IF (NEW.status = '99') THEN
								insert into baseinfo.sc_user_teacher_update
								(
										fk_user,gh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,hyzkm,zzmmm,jkzkm,xyzjm,xxm,
										zp,sfzjyxq,jgh,jtzz,xzz,hkszd,hkxzm,xlm,gzny,lxny,cjny,bzlbm,dabh,dawb,txdz,lxdh,yzbm,dzxx,zydz,tc,
										gwzym,zyrkxd,create_by,create_time,update_by,update_time,jzglbm,jslbm,shzp,gatqwm,jtdh,bgdhw,bgdhn,
										xzzyb,hkszdyb,jtzzyb,txdzyb,cph,zgxl,zgxw,sxzy,zyflm,byyx,bysj,sxhzwy,zwwycd,jszgzshm,sxh,zjzwzgm,
										zjzwzgqdny,zjzw,zjzwrzny,sjxd,xrjzxk,hdrych,hdzjch,grjszw,jgprny,ltxsj,gzdwpk,rsdwpk,zyjszw,hkssqx,
										cjcszy,crjxk,cjcsxl,cjcszyfl,jzxx,gwzw,xzzw,xzzwrzny,shzw,xszw,zfzx,state,status,name,phone,email,
										sex,sfyzl,vocation,talent,yhm,update_date,update_type
								)
								values
								(
										NEW.fk_user,NEW.gh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,NEW.gjdqm,
										NEW.sfzjlxm,NEW.sfzjh,NEW.hyzkm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,NEW.jgh,
										NEW.jtzz,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.xlm,NEW.gzny,NEW.lxny,NEW.cjny,NEW.bzlbm,NEW.dabh,NEW.dawb,
										NEW.txdz,NEW.lxdh,NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.tc,NEW.gwzym,NEW.zyrkxd,NEW.create_by,NEW.create_time,
										NEW.update_by,NEW.update_time,NEW.jzglbm,NEW.jslbm,NEW.shzp,NEW.gatqwm,NEW.jtdh,NEW.bgdhw,NEW.bgdhn,
										NEW.xzzyb,NEW.hkszdyb,NEW.jtzzyb,NEW.txdzyb,NEW.cph,NEW.zgxl,NEW.zgxw,NEW.sxzy,NEW.zyflm,NEW.byyx,
										NEW.bysj,NEW.sxhzwy,NEW.zwwycd,NEW.jszgzshm,NEW.sxh,NEW.zjzwzgm,NEW.zjzwzgqdny,NEW.zjzw,NEW.zjzwrzny,
										NEW.sjxd,NEW.xrjzxk,NEW.hdrych,NEW.hdzjch,NEW.grjszw,NEW.jgprny,NEW.ltxsj,NEW.gzdwpk,NEW.rsdwpk,
										NEW.zyjszw,NEW.hkssqx,NEW.cjcszy,NEW.crjxk,NEW.cjcsxl,NEW.cjcszyfl,NEW.jzxx,NEW.gwzw,NEW.xzzw,
										NEW.xzzwrzny,NEW.shzw,NEW.xszw,NEW.zfzx,NEW.state,NEW.status,NEW.name,NEW.phone,NEW.email,
										NEW.sex,NEW.sfyzl,NEW.vocation,NEW.talent,NEW.yhm,
										cast(NEW.update_time as timestamp),3
								);
								RETURN NEW;
						ELSE
						--sc_user_teacher表执行修改操作时候,把修改的这条新数据放到sc_user_teacher_update表
								insert into baseinfo.sc_user_teacher_update
								(
										fk_user,gh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,hyzkm,zzmmm,jkzkm,xyzjm,xxm,
										zp,sfzjyxq,jgh,jtzz,xzz,hkszd,hkxzm,xlm,gzny,lxny,cjny,bzlbm,dabh,dawb,txdz,lxdh,yzbm,dzxx,zydz,tc,
										gwzym,zyrkxd,create_by,create_time,update_by,update_time,jzglbm,jslbm,shzp,gatqwm,jtdh,bgdhw,bgdhn,
										xzzyb,hkszdyb,jtzzyb,txdzyb,cph,zgxl,zgxw,sxzy,zyflm,byyx,bysj,sxhzwy,zwwycd,jszgzshm,sxh,zjzwzgm,
										zjzwzgqdny,zjzw,zjzwrzny,sjxd,xrjzxk,hdrych,hdzjch,grjszw,jgprny,ltxsj,gzdwpk,rsdwpk,zyjszw,hkssqx,
										cjcszy,crjxk,cjcsxl,cjcszyfl,jzxx,gwzw,xzzw,xzzwrzny,shzw,xszw,zfzx,state,status,name,phone,email,
										sex,sfyzl,vocation,talent,yhm,update_date,update_type
								)
								values
								(
										NEW.fk_user,NEW.gh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,NEW.gjdqm,
										NEW.sfzjlxm,NEW.sfzjh,NEW.hyzkm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,NEW.jgh,
										NEW.jtzz,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.xlm,NEW.gzny,NEW.lxny,NEW.cjny,NEW.bzlbm,NEW.dabh,NEW.dawb,
										NEW.txdz,NEW.lxdh,NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.tc,NEW.gwzym,NEW.zyrkxd,NEW.create_by,NEW.create_time,
										NEW.update_by,NEW.update_time,NEW.jzglbm,NEW.jslbm,NEW.shzp,NEW.gatqwm,NEW.jtdh,NEW.bgdhw,NEW.bgdhn,
										NEW.xzzyb,NEW.hkszdyb,NEW.jtzzyb,NEW.txdzyb,NEW.cph,NEW.zgxl,NEW.zgxw,NEW.sxzy,NEW.zyflm,NEW.byyx,
										NEW.bysj,NEW.sxhzwy,NEW.zwwycd,NEW.jszgzshm,NEW.sxh,NEW.zjzwzgm,NEW.zjzwzgqdny,NEW.zjzw,NEW.zjzwrzny,
										NEW.sjxd,NEW.xrjzxk,NEW.hdrych,NEW.hdzjch,NEW.grjszw,NEW.jgprny,NEW.ltxsj,NEW.gzdwpk,NEW.rsdwpk,
										NEW.zyjszw,NEW.hkssqx,NEW.cjcszy,NEW.crjxk,NEW.cjcsxl,NEW.cjcszyfl,NEW.jzxx,NEW.gwzw,NEW.xzzw,
										NEW.xzzwrzny,NEW.shzw,NEW.xszw,NEW.zfzx,NEW.state,NEW.status,NEW.name,NEW.phone,NEW.email,
										NEW.sex,NEW.sfyzl,NEW.vocation,NEW.talent,NEW.yhm,
										cast(NEW.update_time as timestamp),2
								);
								RETURN NEW;
						END IF;
        ELSIF (TG_OP = 'INSERT') THEN
				--sc_user_teacher表执行新增操作时候,把修改的这条新数据放到sc_user_teacher_update表
						insert into baseinfo.sc_user_teacher_update
						(
								fk_user,gh,ywxm,xmpy,cym,csrq,csdm,jg,mzm,gjdqm,sfzjlxm,sfzjh,hyzkm,zzmmm,jkzkm,xyzjm,xxm,
								zp,sfzjyxq,jgh,jtzz,xzz,hkszd,hkxzm,xlm,gzny,lxny,cjny,bzlbm,dabh,dawb,txdz,lxdh,yzbm,dzxx,zydz,tc,
								gwzym,zyrkxd,create_by,create_time,update_by,update_time,jzglbm,jslbm,shzp,gatqwm,jtdh,bgdhw,bgdhn,
								xzzyb,hkszdyb,jtzzyb,txdzyb,cph,zgxl,zgxw,sxzy,zyflm,byyx,bysj,sxhzwy,zwwycd,jszgzshm,sxh,zjzwzgm,
								zjzwzgqdny,zjzw,zjzwrzny,sjxd,xrjzxk,hdrych,hdzjch,grjszw,jgprny,ltxsj,gzdwpk,rsdwpk,zyjszw,hkssqx,
								cjcszy,crjxk,cjcsxl,cjcszyfl,jzxx,gwzw,xzzw,xzzwrzny,shzw,xszw,zfzx,state,status,name,phone,email,
								sex,sfyzl,vocation,talent,yhm,update_date,update_type
						)
						values
						(
								NEW.fk_user,NEW.gh,NEW.ywxm,NEW.xmpy,NEW.cym,NEW.csrq,NEW.csdm,NEW.jg,NEW.mzm,NEW.gjdqm,
								NEW.sfzjlxm,NEW.sfzjh,NEW.hyzkm,NEW.zzmmm,NEW.jkzkm,NEW.xyzjm,NEW.xxm,NEW.zp,NEW.sfzjyxq,NEW.jgh,
								NEW.jtzz,NEW.xzz,NEW.hkszd,NEW.hkxzm,NEW.xlm,NEW.gzny,NEW.lxny,NEW.cjny,NEW.bzlbm,NEW.dabh,NEW.dawb,
								NEW.txdz,NEW.lxdh,NEW.yzbm,NEW.dzxx,NEW.zydz,NEW.tc,NEW.gwzym,NEW.zyrkxd,NEW.create_by,NEW.create_time,
								NEW.update_by,NEW.update_time,NEW.jzglbm,NEW.jslbm,NEW.shzp,NEW.gatqwm,NEW.jtdh,NEW.bgdhw,NEW.bgdhn,
								NEW.xzzyb,NEW.hkszdyb,NEW.jtzzyb,NEW.txdzyb,NEW.cph,NEW.zgxl,NEW.zgxw,NEW.sxzy,NEW.zyflm,NEW.byyx,
								NEW.bysj,NEW.sxhzwy,NEW.zwwycd,NEW.jszgzshm,NEW.sxh,NEW.zjzwzgm,NEW.zjzwzgqdny,NEW.zjzw,NEW.zjzwrzny,
								NEW.sjxd,NEW.xrjzxk,NEW.hdrych,NEW.hdzjch,NEW.grjszw,NEW.jgprny,NEW.ltxsj,NEW.gzdwpk,NEW.rsdwpk,
								NEW.zyjszw,NEW.hkssqx,NEW.cjcszy,NEW.crjxk,NEW.cjcsxl,NEW.cjcszyfl,NEW.jzxx,NEW.gwzw,NEW.xzzw,
								NEW.xzzwrzny,NEW.shzw,NEW.xszw,NEW.zfzx,NEW.state,NEW.status,NEW.name,NEW.phone,NEW.email,
								NEW.sex,NEW.sfyzl,NEW.vocation,NEW.talent,NEW.yhm,
								cast(NEW.create_time as timestamp),1
						);
						RETURN NEW;
        END IF;
        RETURN NULL; -- result is ignored since this is an AFTER trigger
    END;
$sc_user_teacher_update_audit$ LANGUAGE plpgsql;

--为表sc_user_teacher添加触发器,然后执行的函数
--drop trigger sc_user_teacher_update_audit on baseinfo.sc_user_teacher;
CREATE TRIGGER sc_user_teacher_update_audit
AFTER INSERT OR UPDATE OR DELETE ON baseinfo.sc_user_teacher --在sc_user_teacher表每一行操作之后,执行增删查改时触发
FOR EACH ROW EXECUTE PROCEDURE sc_user_teacher_update_func();--执行的函数


--专家
--创建为触发器执行的函数:
CREATE OR REPLACE FUNCTION sc_user_expert_func() RETURNS TRIGGER AS $sc_user_expert_audit$
    BEGIN
        -- 在sc_user_expert_audit中创建一行以反映在emp上执行的操作,
        -- 使用特殊的变量TG_OP来计算这个操作.
				--sc_user_expert表执行删除操作时候,把删除的这条数据从sc_user表删除(OLD.*表示旧数据,NEW.*表示新数据)
        IF (TG_OP = 'DELETE') THEN
						delete from baseinfo.sc_user where id = OLD.fk_user;
            RETURN OLD;
				--sc_user_expert表执行修改操作时候,把修改的这条新数据放到sc_user表
        ELSIF (TG_OP = 'UPDATE') THEN
						update baseinfo.sc_user
							set
								status = NEW.status,
								update_by = NEW.update_by,
								update_time = NEW.update_time,
								id_number = NEW.sfzjh,
								phone = NEW.phone,
								email = NEW.email,
								name = NEW.name,
								fk_unit = NEW.fk_unit
							where id = OLD.fk_user;
							RETURN NEW;
				--sc_user_expert表执行插入操作时候,把插入的的这条新数据放到sc_user表
        ELSIF (TG_OP = 'INSERT') THEN
						insert into baseinfo.sc_user
						(
							id,type,create_by,create_time,status,name,id_number,phone,fk_unit,email
						)
						values
						(
							NEW.id,'4',NEW.create_by,NEW.create_time,NEW.status,NEW.name,NEW.sfzjh,NEW.phone,NEW.fk_unit,NEW.email
						);
						RETURN NEW;
        END IF;
        RETURN NULL; -- result is ignored since this is an AFTER trigger
    END;
$sc_user_expert_audit$ LANGUAGE plpgsql;

--为表sc_user添加触发器,然后执行的函数
--drop trigger sc_user_expert_audit on baseinfo.sc_user_expert;
CREATE TRIGGER sc_user_expert_audit
AFTER INSERT OR UPDATE OR DELETE ON baseinfo.sc_user_expert --在sc_user表每一行操作之后,执行增删查改时触发
FOR EACH ROW EXECUTE PROCEDURE sc_user_expert_func();--执行的函数

--来宾
--创建为触发器执行的函数:
CREATE OR REPLACE FUNCTION sc_user_guest_func() RETURNS TRIGGER AS $sc_user_guest_audit$
    BEGIN
        -- 在sc_user_guest_audit中创建一行以反映在emp上执行的操作,
        -- 使用特殊的变量TG_OP来计算这个操作.
				--sc_user_guest表执行删除操作时候,把删除的这条数据从sc_user表删除(OLD.*表示旧数据,NEW.*表示新数据)
        IF (TG_OP = 'DELETE') THEN
						delete from baseinfo.sc_user where id = OLD.fk_user;
            RETURN OLD;
				--sc_user_guest表执行修改操作时候,把修改的这条新数据放到sc_user表
        ELSIF (TG_OP = 'UPDATE') THEN
						update baseinfo.sc_user
							set
								status = NEW.status,
								update_by = NEW.update_by,
								update_time = NEW.update_time,
								id_number = NEW.sfzjh,
								phone = NEW.phone,
								email = NEW.email,
								name = NEW.name,
								fk_unit = NEW.fk_unit
							where id = OLD.fk_user;
							RETURN NEW;
				--sc_user_guest表执行插入操作时候,把插入的的这条新数据放到sc_user表
        ELSIF (TG_OP = 'INSERT') THEN
						insert into baseinfo.sc_user
						(
							id,type,create_by,create_time,status,name,id_number,phone,fk_unit,email
						)
						values
						(
							NEW.id,'6',NEW.create_by,NEW.create_time,NEW.status,NEW.name,NEW.sfzjh,NEW.phone,NEW.fk_unit,NEW.email
						);
						RETURN NEW;
        END IF;
        RETURN NULL; -- result is ignored since this is an AFTER trigger
    END;
$sc_user_guest_audit$ LANGUAGE plpgsql;

--为表sc_user添加触发器,然后执行的函数
--drop trigger sc_user_guest_audit on baseinfo.sc_user_guest;
CREATE TRIGGER sc_user_guest_audit
AFTER INSERT OR UPDATE OR DELETE ON baseinfo.sc_user_guest --在sc_user表每一行操作之后,执行增删查改时触发
FOR EACH ROW EXECUTE PROCEDURE sc_user_guest_func();--执行的函数

